package com.gz;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TextParse {

    public static void main(String[] args) {
        String str="【商品】主播同款!!!!!!!\n" +
                "植护原木抽纸*30包整箱家庭装\n" +
                "券后【26.9元】包邮秒杀\n" +
                "----------------------------\n" +
                "【抢券下单】https://s.click.taobao.com/WAasOGw\n" +
                "提示：私聊你的都是骗子！\n" +
                "有问题找：私信客服\n" +
                "【推荐】原生木浆抽纸，环保健康，不含荧光剂，绵软细致，母婴可用，吸水性超强，4层超强韧度！\n" +
                "【下单】￥14q3bsDr5H0￥\n" +
                "复制这条信息,打开[手机淘宝]即可抢购。\n" +
                "\n" +
                "----------------------------\n" +
                "【官网】更多优惠点击http://hxms.dbwspt.com\n" +
                "自助领劵 搜索自己喜爱的商品\n" +
                "没发的商品 点击管理私信";
        System.out.printf(parse(str).toString());
    }

    public static Map<String,String> parse (String str) {
        Pattern p = Pattern.compile("\\s*|\t|\r|\n|");
        Matcher m = p.matcher(str);
        Map<String,String> maps=new HashMap<>();
        String parse=m.replaceAll("");
        parse=parse.replaceAll("!","");
        parse=parse.replaceAll("-","");
        parse=parse.replaceAll("主播同款","");
        maps.put("address",parse.substring(parse.indexOf("https"),parse.indexOf("提示：")));
        int index1 = parse.indexOf("【商品】");
        int index2 = parse.indexOf("券后");
        maps.put("title",parse.substring(index1+4,index2));
        int index4 = parse.indexOf("元】");
        maps.put("price",parse.substring(index2+3,index4));
        parse=parse.substring(index4,parse.length()-1);
        int index5 = parse.indexOf("【推荐】");
        int index6 = parse.indexOf("【下单】");
        maps.put("content",parse.substring(index5+4,index6));
        int index7 = parse.indexOf("￥");
        int index8 = parse.lastIndexOf("￥");
        maps.put("code",parse.substring(index7,index8+1));
        return  maps;
    }
}
